<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_display_component_class.php");
	require_once(CUTEENGINE_NAMESPACES_PATH."javascript_namespace.php");
    require_once(CUTEENGINE_NAMESPACES_PATH."url_parameters_namespace.php");
	require_once(CUTEENGINE_BASE_COMPONENTS_PATH."content_loader_class.php");
    require_once(CUTEENGINE_BASE_COMPONENTS_PATH."css_parser_class.php");
    //
    // t_component_inspector
    //
	class t_component_inspector extends t_base_display_component
	{	
		
        // argoument field name
		// G
		const language_position_last = 1;
		// M
		const main_url_argument_component_id = "component_id";
        const main_url_argument_component_style = "component_style";
		
        // S
        const specific_parameters_position_last = 1;
		
		// method
		// protected
		// G
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
        static function get_help_specific_parameter($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::specific_parameters_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_specific_parameter($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			switch ($a_index) 
            {
                /*case self::specific_parameters_position_:
					$local_return = 'TRUE';
				break;                */
			}
			return $local_return;
		}		
        protected function get_specific_parameters_position_last()
        {
            return self::specific_parameters_position_last;
        }	
		// I
		protected function initialize_query_parameters()
		{
		    
		}		
		// property
		// public		
		// C
		public $content_loader = null; //t_content_loader;
        // method name
		const main_url_method_save_component_style_to_database = "save_component_style_to_database";
        const main_url_method_save_component_style_to_database_label = "save_component_style_to_database";        
		// method
		// protected
		//C
		protected function create_tags_structure()
		{
            global $g_ambient_namespace;
            global $g_cuteengine;
			global $g_javascript_namespace;
            //
            if (! $this->main_tag)
			{
				//
				$this->main_tag = new t_base_tag(t_base_tag_type::btt_div,$this->name);
				$this->main_tag->include_child_str = true;
				
				$local_header_script_generator = $this->main_tag->header_script_generator;
                //
                //
				$tag_main_moving_class_name = $this->name."_class";
                $this->main_tag->class_name = $tag_main_moving_class_name;
                $local_header_script_generator->add_style_sheet_property("#$this->name","left","5px");
				$local_header_script_generator->add_style_sheet_property("#$this->name","right","400px");
				$local_header_script_generator->add_style_sheet_property("#$this->name","top","5px");
				$local_header_script_generator->add_style_sheet_property("#$this->name","bottom","150px");
				$this->main_tag->add_style_property("z-index","500");
				//$this->main_tag->set_editing_tags(true);
                //echo "PRIMA compute_tags_structure OK";
				$this->compute_tags_structure();
				
				
			}
		}

		
		// public
		public function __construct($a_cuteengine_component,$a_query_parameter) 
		{
			global $g_javascript_namespace;
			$this->content_loader = new t_content_loader($g_javascript_namespace,$this);
			$this->content_loader->initialize_parameter($this->name."_log",
				$this->name."_log",'undefined','undefined',
				'undefined','undefined',false);
			parent::__construct($a_cuteengine_component,$a_query_parameter);
			if ($this->name == 'component_inspector')
				exit("ERROR, the 't_component_inspector' class object can't be called with the name 'component_inspector'.");
			// url array
            $this->new_url_argument(self::main_url_argument_component_id,
				1);    
            $this->new_url_argument(self::main_url_argument_component_style,
				2);		
            $this->new_url_method(self::main_url_method_save_component_style_to_database,
                self::main_url_method_save_component_style_to_database_label);    

		}	
		
		// C
		public function create_internal_parts()
        {
			global $g_database_namespace;
            parent::create_internal_parts();
			//echo __METHOD__  . "<br>";
			// MAIN FORM	
            $this->part = $this->add_new_part(-1,1,t_form_part,'@'.$this->name.'_part@@@',"",
				//fields
				"@|t_field_inspector|".$this->name."_inspector|-1|@",
				// action 1
				""
                ,1);  
           
			//

        }		
		//D
			/*	public function display_component()
		{
			parent::display_component();
		}*/
		// E
		public function execute_component_action()
		{
			$local_function = parent::execute_component_action();
            if ($local_function)
			{
				$this->$local_function();
            }
			else
			{
				 
			}
			//echo "argomento: ".$this->url_argument(self::main_url_argument_import_file_name);
			//$this->parse_source();
		}
      
		// S
		public function save_component_style_to_database()
		{
            echo __METHOD__;
            $local_name = $this->url_argument(self::main_url_argument_component_id);            
            $local_style = str_replace('::','#',$this->url_argument(self::main_url_argument_component_style));
			//echo "local_style:$local_style";
            //  imports style from URL
            $local_css_parser_from_url = new t_css_parser;
            $local_css_parser_from_url->import_css_style($local_style);
            // imports stylr from file
            $local_style = $this->get_style_from_file($local_name);
            $local_css_parser_from_file = new t_css_parser;
            $local_css_parser_from_file->import_css_style($local_style);
			//
			$local_css_parser_from_file->import_from_another_parser($local_css_parser_from_url);
            //echo $local_css_parser_from_file->compute_style_string();
			$this->export_style_sheet_to_file($local_name,
                $local_css_parser_from_file->compute_style_string(),true);
            //echo $this->url_argument(self::main_url_argument_component_style);
        }
	}
?>